<?php

namespace app\admin\controller\lal;

use app\common\controller\Backend;
use think\Db;

/**
 * 拉卡拉一次分账
 *
 * @icon fa fa-circle-o
 */
class Entry extends Backend
{

    /**
     * Entry模型对象
     * @var \app\admin\model\lal\Entry
     */
    protected $model = null;
    protected $shop_model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\lal\Entry;
        $this->shop_model = new \app\admin\model\store\Shop;

    }

    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if (false === $this->request->isAjax()) {
            return $this->view->fetch();
        }
        //如果发送的来源是 Selectpage，则转发到 Selectpage
        if ($this->request->request('keyField')) {
            return $this->selectpage();
        }
        [$where, $sort, $order, $offset, $limit] = $this->buildparams();
        $list = $this->model
            ->where($where)
            ->order($sort, $order)
            ->paginate($limit);
        $total = $list->total();
        $rows = $list->items();
        if ($total > 0) {
            foreach ($rows as $key => &$value) {
                $value['shopname'] = $this->shop_model->where('id',$value['shop_id'])->value('shopname');
            }
        }
        $result = ['total' => $total, 'rows' => $rows];
        return json($result);
    }

}
